<template>
  <ul class="approval-flow">
    <li v-for="item in recordList" :key="item.id" class="approval-flow-item">
      <div class="approval-flow-item-tail"></div>
      <div class="approval-flow-item-head">
        <UserAvatar :user="item"></UserAvatar>
        <span class="approval-status-icon refuse" v-if="item.result === 'REFUSE'"></span>
        <span class="approval-status-icon agree" v-else></span>
      </div>
      <div class="approval-flow-item-content">
        <div class="flow-item-title">
          <span>{{ getItemTitle(item) }}</span>
          <span class="flow-item-title-time">{{ item.date }}</span>
        </div>
        <template v-if="item.type === 'PROCESS_CC'">
          <div class="send-copy">
            <div class="send-copy-title cf">
              <span>已抄送{{ item.ccUserNames.length }}人</span>
              <!-- <span class="text-primary margin-left">全部已读</span> -->
              <span class="fr icon-up" :class="{ down: item.hideUsers }" @click="toggleHideUsers(item)"></span>
            </div>
          </div>
          <div class="ulListWrap" v-show="!item.hideUsers">
            <a-space class="spaceWrap" style="width: auto;" :wrap="true">
              <div style="margin: 4px 0px;" v-for="user in item.ccUserNames" :key="user">
                <UserAvatar :size="44" :user="{ userName: user }"></UserAvatar>
                <div class="margin-top-xs name">{{ user }}</div>
              </div>
            </a-space>
          </div>
        </template>
        <div v-else class="flow-item-username" style="color:#000000">
          {{ item.userName }}
        </div>
        <div class="flow-item-remark" v-if="item.remark">
          {{ item.remark }}
        </div>
      </div>
    </li>
  </ul>
</template>

<script>
import UserAvatar from './UserAvatar.vue';
export default {
  components: { UserAvatar },
  props: {
    data: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {};
  },
  computed: {
    recordList() {
      return this.data.map(item => {
        if (item.type === 'PROCESS_CC') {
          item.userIcon = require('@/assets/svg/icon-laba.svg');
        }
        if (item.userId === 'bpms_system') {
          item.userIcon = require('@/assets/svg/icon-system.svg');
        }
        return item;
      });
    },
  },
  created() { },
  methods: {
    toggleHideUsers(item) {
      this.$set(item, 'hideUsers', !item.hideUsers);
    },
    getItemTitle(item) {
      if (item.activityName) {
        return item.activityName;
      }
      if (item.userId === 'bpms_system') {
        return '系统';
      }
      const map = {
        START_PROCESS_INSTANCE: '发起申请',
        PROCESS_CC: '审批人（抄送或签审批人）',
        EXECUTE_TASK_NORMAL: '审批人',
        EXECUTE_TASK_AGENT: '代理人审批',
        APPEND_TASK_BEFORE: '前加签',
        APPEND_TASK_AFTER: '后加签',
        REDIRECT_TASK: '转交',
        TERMINATE_PROCESS_INSTANCE: '撤销申请',
        FINISH_PROCESS_INSTANCE: '结束申请',
        ADD_REMARK: '添加评论',
        REDIRECT_PROCESS: '审批退回',
      };
      return map[item.type] || '审批人';
    },
  },
};
</script>

<style lang="less" scoped>
.approval-flow {
  color: #fff;

  .approval-flow-item {
    position: relative;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin: 0;
    // padding: 16px 0;
    padding-bottom: 32px;
    font-size: 14px;
    list-style: none;

    &:last-child .approval-flow-item-tail {
      display: none;
    }

    .approval-flow-item-tail {
      position: absolute;
      top: 62px;
      left: 27px;
      height: calc(100% - 64px);
      border-left: 2px solid #cdcdcd;
    }

    .approval-flow-item-head {
      position: absolute;
      width: 60px;
      height: 60px;
      top: 0;
      left: 0;

      .approval-status-icon {
        position: absolute;
        right: -9px;
        bottom: -4px;
        width: 30px;
        height: 30px;
        background-repeat: no-repeat;
        background-size: contain;

        &.agree {
          background-image: url(~@/assets/svg/icon-agree.svg);
        }

        &.refuse {
          background-image: url(~@/assets/svg/icon-refuse.svg);
        }
      }
    }

    .approval-flow-item-content {
      position: relative;
      margin-left: 80px;
      margin-bottom: 8px;
      // height: 60px;
      word-break: break-word;

      .flow-item-title-time {
        font-size: 16px;
        font-weight: 500;
        color: #000000;
      }

      .flow-item-title {
        display: flex;
        justify-content: space-between;
        font-size: 16px;
        font-weight: 900;
        color: #000000;
      }

      .flow-item-username,
      .send-copy-title {
        margin-top: 8px;
        font-size: 16px;
        font-weight: 400;
        color: rgba(255, 255, 255, 0.8);
      }

      .send-copy-title .icon-up {
        width: 28px;
        height: 15px;
        background-image: url(~@/assets/svg/icon-up.svg);
        background-size: contain;
        background-repeat: no-repeat;
        cursor: pointer;
        transition: transform 0.5s;

        &.down {
          transform: rotate(180deg);
          transform-origin: center;
        }
      }

      .send-copy-list {
        margin-top: 20px;
        display: flex;

        .send-copy-user {
          width: 60px;
          color: rgba(255, 255, 255, 0.8);
        }
      }

      .flow-item-remark {
        margin-top: 16px;
        padding: 10px;
        background: rgba(255, 255, 255, 0.2);
        font-size: 16px;
        font-weight: 400;
        // color: rgba(255, 255, 255, 0.9);
        color: #000000;
        border-radius: 5px;
      }
    }
  }
}
.name{
  color: #000000;
}

.ulListWrap {
  width: 100%;
  margin: 12px 0px;

  .ul {
    display: flex;
    padding: 0px;
  }

  .spaceWrap {
    display: flex;
    flex-wrap: wrap;

    .name {
      width: 100%;
      text-align: center;
    }
  }
}
</style>
